﻿using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;

namespace Collab.Modules.ViewTracker
{
    #region Adornment Factory

    [Export(typeof(IWpfTextViewCreationListener))]
    [ContentType("text")]
    [TextViewRole(PredefinedTextViewRoles.Document)]
    internal sealed class ViewTracker : IWpfTextViewCreationListener
    {

        /// <summary>
        /// Defines the adornment layer for the highlighting. This layer is ordered 
        /// before the selection layer in the Z-order
        /// </summary>
        [Export(typeof(AdornmentLayerDefinition))]
        [Name("HighlightAdornment")]
        [Order(Before = PredefinedAdornmentLayers.Selection)]
        [TextViewRole(PredefinedTextViewRoles.Document)]
        public AdornmentLayerDefinition editorAdornmentLayer = null;
        
        /// <summary>
        /// Instantiates a ViewTracker manager when a textView is created.
        /// </summary>
        /// <param name="textView">The <see cref="IWpfTextView"/> upon which the adornment should be placed</param>
        public void TextViewCreated(IWpfTextView textView)
        {
            HighlightManager.AddView(textView);

            textView.Closed += (sender, e) =>
            {
                HighlightManager.RemoveView(textView);
            };


        }

        


    }
    #endregion //Adornment Factory
}
